package com.controller;

import com.dto.excution.ListExcution;
import com.entity.*;
import com.enums.ListEnum;
import com.service.LocationService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Administrator on 2019/1/4 0004.
 */
@RequestMapping("/location")
@RestController
public class LocationController {
    @Autowired
    private LocationService service;

    @ApiOperation(value = "新增用户定位信息")
    @PostMapping(value = "/addLocation")
    @ResponseBody
    public ListExcution<Void> addLocation(Integer userId,String latitude,String longitude,String address){
        int count = service.addLocation(userId,latitude,longitude,address);
        if(count > 0){
            return new ListExcution<Void>(null, ListEnum.ADDSUCCESS);
        }else{
            return new ListExcution<Void>(null, ListEnum.ADDFAIL);
        }
    }

    @ApiOperation(value = "查城市")
    @PostMapping(value = "/findCity")
    @ResponseBody
    public ListExcution<List<CityInfo>> findCity(){
        List<CityInfo> list = service.findCity();
        return new ListExcution<List<CityInfo>>(list, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "查籍贯")
    @PostMapping(value = "/findBirthPlace")
    @ResponseBody
    public ListExcution<List<BirthPlaceInfo>> findBirthPlace(){
        List<BirthPlaceInfo> list = service.findBirthPlace();
        return new ListExcution<List<BirthPlaceInfo>>(list, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "查科目")
    @PostMapping(value = "/findSubject")
    @ResponseBody
    public ListExcution<List<SubjectInfo>> findSubject(){
        List<SubjectInfo> list = service.findSubject();
        return new ListExcution<List<SubjectInfo>>(list, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "根据城市查学校")
    @PostMapping(value = "/findSchool")
    @ResponseBody
    public ListExcution<List<SchoolInfo>> findSchool(String cityName){
        List<SchoolInfo> list = service.findSchool(cityName);
        return new ListExcution<List<SchoolInfo>>(list, ListEnum.SUCCESS);
    }
    @ApiOperation(value = "查学校")
    @PostMapping(value = "/findSchool1")
    @ResponseBody
    public ListExcution<List<SchoolInfo>> findSchool1(){
        List<SchoolInfo> list = service.findSchool1();
        return new ListExcution<List<SchoolInfo>>(list, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "根据城市查地区")
    @PostMapping(value = "/findArea")
    @ResponseBody
    public ListExcution<List<AreaInfo>> findArea(String cityName){
        List<AreaInfo> list = service.findArea(cityName);
        return new ListExcution<List<AreaInfo>>(list, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "查询城市下的区")
    @PostMapping(value = "findDistrict")
    @ResponseBody
    public ListExcution<List<DistrictInfo>> findDistrict(Integer cityId){
        List<DistrictInfo> location=service.findDistrict(cityId);
        return new ListExcution<List<DistrictInfo>>(location, ListEnum.SUCCESS);
    }

    //差专业
    @ApiOperation(value = "查询专业")
    @PostMapping(value = "findMajor")
    @ResponseBody
    public ListExcution<List<MajorInfo>> findMajor(){
        List<MajorInfo> major = service.findMajor();
        return new ListExcution<List<MajorInfo>>(major, ListEnum.SUCCESS);
    }
}
